#include "my_lcd.h"
#include "stdarg.h"

char password[3]={'0','0','0'};
char pass_change[3]={'0','0','0'};
void lcd_sprintf(uint8_t Line , char *format , ...)
{
	char String[21];
    va_list arg;
    va_start(arg,format);
    vsprintf(String,format,arg);
    va_end(arg);
    LCD_DisplayStringLine(Line,(u8 *)String);
}

uint16_t count;
uint8_t show_mode;//0为输入，1为修改
uint8_t input_position;//输入位置
uint8_t pass;//1密码正确
void lcd_proc(void)
{
	
	
	//lcd_sprintf(Line6,"        %c  %c  %c",actually_password[0],actually_password[1],actually_password[2]);
    if(show_mode==0)//输入
    {
		cled[0] = 1;
		cled[1] = 0;
        lcd_sprintf(Line1,"        Lock     ");
        lcd_sprintf(Line3,"      Pass Word     ");
        switch (input_position)
        {
            case 0:
				lcd_sprintf(Line4,"       %c %c %c",input_password,'*','*'); 
				break;
            case 1:
				lcd_sprintf(Line4,"       %c %c %c",password[0],input_password,'*'); 
				break;
            case 2:
				lcd_sprintf(Line4,"       %c %c %c",password[0],password[1],input_password); 
				break;
			case 3:
				if(pass)
				{
					show_mode = 1;
					input_position = 0;
				}
				else
				{
					show_mode = 0;
					input_position = 0;
				}
				break;
        }
               
    }
    else if(show_mode==1)//输出
    {
		cled[0] = 0;
		cled[1] = 1;
        lcd_sprintf(Line1,"        Set     ");
        lcd_sprintf(Line3,"       Change     ");
        switch (input_position)
        {
            case 0:
				lcd_sprintf(Line4,"       %c %c %c",input_password,'*','*'); 
				break;
            case 1:
				lcd_sprintf(Line4,"       %c %c %c",pass_change[0],input_password,'*'); 
				break;
            case 2:
				lcd_sprintf(Line4,"       %c %c %c",pass_change[0],pass_change[1],input_password); 
				break;
			case 3:
				if(pass)
				{
					show_mode = 1;
					input_position = 0;
				}
				else
				{
					show_mode = 0;
					input_position = 0;
				}
				break;
        }
    }


	count++;
}

uint8_t input_password1;
void time_proc(void)
{
	
	if(third_time_flag == 1 )
	{
		uint32_t now_time = HAL_GetTick();
		if(now_time  >=3000+old_time)
		{
			third_time_flag = 0;
			show_mode = 0;
			input_position = 0;
		}
	}
	if((input_password1 != input_password))
	{
		old_time = HAL_GetTick();
	}
	input_password1 =  input_password;
}